/*****************************************************************************************
This file is a part of Arise library.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

Arise Engine		Console.h

					E-mail:		arise_engine@mail.ru

created:			13.09.2008
last changes:		13.09.2008
*****************************************************************************************/
#pragma once

#include "..\renderer\IScene2d.h"

#define CONSOLE_MAX_COLORS	8


struct ConsoleString
{
	std::string	string;
	DWORD		color;
};


class Console
{
private:

	IScene2d*		m_scene;
	EditControl		m_edit;
	Sprite*			m_background;
	Font*			m_font;
	UINT			m_num_strings_visible;
	float			m_offset_width;
	float			m_offset_height;
	int				m_current_string;
	DWORD			m_colors[CONSOLE_MAX_COLORS];
	
	std::vector<ConsoleString>	m_strings;

	void ShowStrings(UINT start_string);

public:
	Console();
	virtual ~Console();

	bool Init(IScene2d* scene);
	void Update(float delta_time);
	void Render();
	void Release();

	void AddString(const std::string& string, UINT color = 0);
	void KeyClick(int key, int character);
	void LineUp()	{m_current_string--; if(m_current_string < 0) m_current_string = 0;}
	void LineDown()	{m_current_string++; if(m_current_string+m_num_strings_visible >= (int)m_strings.size()) m_current_string = (int)m_strings.size() - m_num_strings_visible;}
	void PageUp()	{m_current_string -= m_num_strings_visible; if(m_current_string < 0) m_current_string = 0;}
	void PageDown()	{m_current_string += m_num_strings_visible; if(m_current_string+m_num_strings_visible >= (int)m_strings.size()) m_current_string = (int)m_strings.size() - m_num_strings_visible;}
	void Home()		{m_current_string = 0;}
	void End()		{m_current_string = (int)m_strings.size() - m_num_strings_visible;}
};

